package com.yaozheng.vocationaltraining.fragment;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.iview.limited.ITimedPaperView;
import com.yaozheng.vocationaltraining.service.impl.limited.TimedPaperServiceImpl;
import com.yaozheng.vocationaltraining.service.limited.TimedPaperService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

import net.sf.json.JSONObject;

/**
 * 考试菜单栏
 *
 * @author Administrator
 */
@EFragment(R.layout.fragment_exam)
public class ExamMenuFragment extends BaseFragment implements ITimedPaperView {
    @ViewById
    TextView headTitleText;
//    @Bean(TimedPaperServiceImpl.class)
//    TimedPaperService timedPaperService;

    public HomeActivity getHomeActivity() {
        return (HomeActivity) getActivity();
    }

    @AfterViews
    public void initView() {
//        timedPaperService.init(this);
        headTitleText.setText("考试");
    }


    /**
     * 随堂检测点击,每日一侧
     */
    @Click({R.id.quizPreviewLayout, R.id.detectionQuizLayout})
    public void detectionQuizClick(View view) {
//		getBaseActivity().setIntentString("examType",
//				String.valueOf(view.getTag()));
        getBaseActivity().setIntentString("examType", "3");
        getHomeActivity().openPaperCatalogFragment();
    }

    /**
     * 大师之路点击
     */
    @Click({R.id.grandmasterLayout})
    public void grandmasterCLick() {
//        Intent intent = new Intent();
//        intent.setClassName(getActivity(),
//                Constants.MASTER_ACTIVITY_CLASS_NAME);
//        getActivity().startActivity(intent);
        getHomeActivity().openMasterFragment();
    }

    /**
     * 闯关模式点击
     */
    @Click(R.id.advancedCheckpointsLayout)
    public void advancedCheckpointsClick() {
//        Intent intent = new Intent();
//        intent.setClassName(getActivity(),
//                Constants.CHECKPOINTS_TRIP_ACTIVITY_CLASS_NAME);
//        startActivity(intent);
        getHomeActivity().openCheckpointsTripFragment();
    }

    /**
     * 极限挑战
     */
    @Click(R.id.limitLayout)
    public void limitClick() {
//        showOperatingProgressDialog("取试题中");
//        timedPaperService.createPapper();
        getHomeActivity().openLimitedChallengeFragment();
    }

    /**
     * PK赛
     */
    @Click(R.id.pkLayout)
    public void pkClick() {
        getHomeActivity().openPKFragment();
    }

    /**
     * 我的考试
     */
    @Click(R.id.my_examLayout)
    public void myExamClick() {
        getHomeActivity().openMyExamFragment();
    }

    /**
     * 创建试卷成功
     *
     * @param jsonObject
     */
    @UiThread
    @Override
    public void createPapperSuccess(JSONObject jsonObject) {
        cancelOperatingProgressDialog();
        JSONObject paperJsonObject = TypeUtils.getJsonObject(jsonObject, "data", "paper");
        int id = TypeUtils.getJsonInteger(paperJsonObject, "id");
        Intent intent = getBaseActivity().getIntent();
        intent.putExtra("examType", "5");
        intent.putExtra("paperId", id);
        intent.putExtra("questionJsonObject", paperJsonObject.toString());
        intent.putExtra("examTitle", "限时挑战");
        getHomeActivity().openOnlineExamFragment();
    }

    @UiThread
    @Override
    public void createPapperError(String error) {
        cancelOperatingProgressDialog();
        alertMessage(error);
    }

    // /**
    // * 每日一侧
    // */
    // public void quizzesClick() {
    // Intent intent = new Intent();
    // intent.setClassName(getContext(),
    // Constants.ONLINE_EXAM_ACTIVITY_CLASS_NAME);
    // getContext().startActivity(intent);
    // }
}
